<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Facades\Utils\QiniuFileManager;

class Cases extends Model
{
    protected $table = 'cases';

    protected $fillable = [
    	'id',
    	'case_type',
        'title',
        'desc',
    	'name',
    	'age',
    	'sex',
    	'province_id',
    	'city_id',
    	'manner',
    	'time',
    	'height',
        'user_name',
        'history',
    	'introduce',
        'picture'
    ];

    public function front(){
        return $this->hasOne('App\Models\Front', 'case_id');
    }

    public function rear(){
        return $this->hasOne('App\Models\Rear', 'case_id');
    }

    public function province()
    {
        return $this->belongsTo('App\Models\Province','province_id');
    }

    public function city()
    {
        return $this->belongsTo('App\Models\City','city_id');
    }

    protected $appends=[
        'picture_url'
    ];

    public function getPictureUrlAttribute()
    {
        if(isset($this->attributes['picture'])){
            return $this->attributes['picture_url']=QiniuFileManager::getFileUrl($this->attributes['picture'],'public');
        }
    }
}
